Skip to content

normalize-yaml: Enhance to collapse spacing#9980

Merged
aduth merged 4 commits intomainfrom
aduth-normalize-yaml-collapse-spaces
Jan 29, 2024
Merged

normalize-yaml: Enhance to collapse spacing#9980
aduth merged 4 commits intomainfrom
aduth-normalize-yaml-collapse-spaces

Conversation

@aduth
Copy link
Copy Markdown
Contributor

@aduth aduth commented Jan 26, 2024

🛠 Summary of changes

Adds new behavior to the YAML normalization package to collapse spacing between sentences in YAML content.

Related discussion: https://gsa-tts.slack.com/archives/CEUQ9FXNJ/p1706111249614589

📜 Testing Plan

Verify that make lint_yaml is produces a successful exit code.

  1. make lint_yaml
  2. echo $?
  3. Observe: 0

Verify that reverting included normalizations and running normalization applies the changes to collapse spaces

  1. git checkout main -- config/locales
  2. make normalize_yaml
  3. git add config/locales
  4. git status
  5. Observe "nothing to commit, working tree clean"

Verify that included specs pass:

  1. yarn mocha app/javascript/packages/normalize-yaml/index.spec.js

Copy link
Copy Markdown
Contributor

@mitchellhenke mitchellhenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 👍🏼 👍🏼 👍🏼 👍🏼

Copy link
Copy Markdown
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this isn't strictly necessary because HTML collapses extra spaces, so it's just for consistency in source?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ how come we need the capture group? My expectation is that we could just grab the spaces and period?

Suggested change
node.value = node.value.replace(/(\w)\. {2,}/g, '$1. ');
node.value = node.value.replace(/\. {2,}/g, '. ');

Copy link
Copy Markdown
Contributor Author

@aduth aduth Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ how come we need the capture group? My expectation is that we could just grab the spaces and period?

In my mind I was thinking the capture group helped assure that it was actually a sentence of English (French, etc.) text vs. some garbled symbols or some other non-"sentence" content like a numbered list, but (a) that's probably unlikely and (b) we may want the spacing collapse for those scenarios anyways?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree we'd want to collapse anyways, and we could make the rule smarter if we run into issues in the future as needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's safe to even go so far as to collapse all multiple spaces everywhere, regardless of whether it occurs after a period? The resulting diff from existing issues seems reasonable.

diff --git a/app/javascript/packages/normalize-yaml/visitors/collapse-sentence-spacing.js b/app/javascript/packages/normalize-yaml/visitors/collapse-sentence-spacing.js
index 1ac577e9af..e4f5eaf8b1 100644
--- a/app/javascript/packages/normalize-yaml/visitors/collapse-sentence-spacing.js
+++ b/app/javascript/packages/normalize-yaml/visitors/collapse-sentence-spacing.js
@@ -3,3 +3,3 @@ export default /** @type {import('yaml').visitor} */ ({
     if (typeof node.value === 'string') {
-      node.value = node.value.replace(/(\w)\. {2,}/g, '$1. ');
+      node.value = node.value.replace(/ {2,}/g, ' ');
     }
diff --git a/config/locales/titles/fr.yml b/config/locales/titles/fr.yml
index ed8e21acab..c79bac9bf3 100644
--- a/config/locales/titles/fr.yml
+++ b/config/locales/titles/fr.yml
@@ -47,3 +47,3 @@ fr:
       suggest_second_mfa: Vous avez ajouté votre première méthode d’authentification !
-        Ajoutez-en une deuxième  en guise de sauvegarde.
+        Ajoutez-en une deuxième en guise de sauvegarde.
     no_auth_option: Aucun message de connexion trouvé
diff --git a/config/locales/user_mailer/en.yml b/config/locales/user_mailer/en.yml
index 0a68b4b203..aaa84453c1 100644
--- a/config/locales/user_mailer/en.yml
+++ b/config/locales/user_mailer/en.yml
@@ -285,3 +285,3 @@ en:
       gpo_letter_header: Your letter is on the way
-      header: To finish resetting your password, please click the link below  or copy
+      header: To finish resetting your password, please click the link below or copy
         and paste the entire link into your browser.
diff --git a/config/locales/zxcvbn/fr.yml b/config/locales/zxcvbn/fr.yml
index cea1f76730..01666fb39f 100644
--- a/config/locales/zxcvbn/fr.yml
+++ b/config/locales/zxcvbn/fr.yml
@@ -28,3 +28,3 @@ fr:
         Les répétitions comme « abcabcabc » sont à peine
-                 plus difficiles à deviner que « abc »
+         plus difficiles à deviner que « abc »
       reversed_words_arent_much_harder_to_guess: Les mots inversés ne sont pas très difficiles à deviner

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave that ⬆️ a try in rebased 0391204

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@aduth
Copy link
Copy Markdown
Contributor Author

aduth commented Jan 26, 2024

this isn't strictly necessary because HTML collapses extra spaces, so it's just for consistency in source?

That's a good point to highlight. Technically it's not always so simple, but that's largely true, yes. There could be cases where these strings are used in SMS or email messages, which may not necessarily work the same, but also probably an edge case.

But similar to line length (Prettier) formatting, I think it's fair to say that source consistency is a big factor, yes.

aduth and others added 4 commits January 29, 2024 09:13
changelog: User-Facing Improvements, Content, Improve consistency of spacing between content sentences
See: #9980 (comment)

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
@aduth aduth force-pushed the aduth-normalize-yaml-collapse-spaces branch from 1375ad8 to 0391204 Compare January 29, 2024 14:13
@aduth aduth changed the title normalize-yaml: Enhance to collapse spacing between sentences normalize-yaml: Enhance to collapse spacing Jan 29, 2024
@aduth aduth merged commit 4f16570 into main Jan 29, 2024
@aduth aduth deleted the aduth-normalize-yaml-collapse-spaces branch January 29, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants